<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是Git中贮藏与清理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Git-04-Git本地仓库-10-贮藏与清理">
<meta property="og:url" content="https://sumumm.github.io/post/5abe0a5e.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是Git中贮藏与清理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624202757705.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624202832487.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624203432533.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624074209583.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624080518416.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204122573.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204424836.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204534493.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624205116412.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624205600592.png">
<meta property="article:published_time" content="2023-07-02T07:14:31.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.070Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624202757705.png">


<link rel="canonical" href="https://sumumm.github.io/post/5abe0a5e.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/5abe0a5e.html","path":"post/5abe0a5e.html","title":"LV01-Git-04-Git本地仓库-10-贮藏与清理"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Git-04-Git本地仓库-10-贮藏与清理 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="nav-text">一、应用场景</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E4%BB%93%E5%BA%93%E5%87%86%E5%A4%87"><span class="nav-text">二、仓库准备</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%93%E5%BA%93%E5%B9%B6%E6%8F%90%E4%BA%A4"><span class="nav-text">1. 初始化仓库并提交</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E4%B8%8E%E6%8F%90%E4%BA%A4%E8%AE%B0%E5%BD%95"><span class="nav-text">2. 文件内容与提交记录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-master%E5%88%86%E6%94%AF"><span class="nav-text">2.1 master分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-dev%E5%88%86%E6%94%AF"><span class="nav-text">2.2 dev分支</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%B4%AE%E8%97%8F%E5%B7%A5%E4%BD%9C"><span class="nav-text">三、贮藏工作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BA%A7%E7%94%9F%E6%96%87%E4%BB%B6%E6%94%B9%E5%8A%A8"><span class="nav-text">1. 产生文件改动</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF"><span class="nav-text">2. 切换分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E8%B4%AE%E8%97%8F%E4%BF%AE%E6%94%B9"><span class="nav-text">3. 贮藏修改</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">3.1 命令说明</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">3.2 使用实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%9F%A5%E7%9C%8B%E8%B4%AE%E8%97%8F%E5%86%85%E5%AE%B9"><span class="nav-text">4. 查看贮藏内容</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">4.1 命令说明</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E8%B4%AE%E8%97%8F%E4%BF%A1%E6%81%AF%E8%AF%B4%E6%98%8E"><span class="nav-text">4.2 贮藏信息说明</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">4.3 使用实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E5%BA%94%E7%94%A8%E8%B4%AE%E8%97%8F"><span class="nav-text">四、应用贮藏</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">1. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">2. 使用实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%8F%AF%E8%83%BD%E4%BC%9A%E4%BA%A7%E7%94%9F%E5%86%B2%E7%AA%81%EF%BC%9F"><span class="nav-text">4. 可能会产生冲突？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%9B%9E%E5%88%B0%E8%B4%AE%E8%97%8F%E7%9A%84%E7%8A%B6%E6%80%81%EF%BC%9F"><span class="nav-text">5. 回到贮藏的状态？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">5.1 命令说明</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">5.2 使用实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E7%A7%BB%E9%99%A4%E8%B4%AE%E8%97%8F"><span class="nav-text">五、移除贮藏</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%83%85%E5%86%B5%E8%AF%B4%E6%98%8E"><span class="nav-text">1. 情况说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">2. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">3. 使用实例</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/5abe0a5e.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Git-04-Git本地仓库-10-贮藏与清理 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Git-04-Git本地仓库-10-贮藏与清理
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 15:14:31" itemprop="dateCreated datePublished" datetime="2023-07-02T15:14:31+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">开发工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" itemprop="url" rel="index"><span itemprop="name">03版本控制</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>14 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是Git中贮藏与清理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">Git 官网</td><td align="left"><a href="https://git-scm.com/" target="_blank">https://git-scm.com/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 官方文档</td><td align="left"><a href="https://git-scm.com/doc" target="_blank">https://git-scm.com/doc <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Pro Git Book</td><td align="left"><a href="https://git-scm.com/book/zh/v2" target="_blank">https://git-scm.com/book/zh/v2 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 快速使用指南</td><td align="left"><a href="https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/" target="_blank">https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Visual Git Cheat Sheet</td><td align="left"><a href="https://ndpsoftware.com/git-cheatsheet.html#loc=index" target="_blank">https://ndpsoftware.com/git-cheatsheet.html#loc=index <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<p>【说明】本节笔记的相关操作在Windows下进行，因为VS Code有个Git的插件，可以很直观的演示一些东西。由于Git安装后自带一个Git-Bash终端，所以就不用Win下的命令行啦，就用的这个终端，因为它里边的命令与Linux很类似，而windows中的命令行有些命令与linux并不相同，为了统一，还是用用Git自带的终端啦。另外VS Code是可以选择使用的终端的，我直接将VS Code使用的终端改成了git-bash，这样更方便一些。</p>
<h1 id="一、应用场景"><a href="#一、应用场景" class="headerlink" title="一、应用场景"></a><font size=3>一、应用场景</font></h1><p>有时，当我们在项目的一部分上已经工作一段时间后，所有东西都进入了混乱的状态， 而这时我们想要切换到另一个分支做一点别的事情。 问题是，我们不想仅仅因为过会儿回到这一点而为做了一半的工作创建一次提交。 针对这个问题的答案是 <code>git stash</code> 命令。</p>
<p><strong>贮藏（stash）</strong>会处理工作目录的脏的状态——即跟踪文件的修改与暂存的改动——然后将未完成的修改保存到一个栈上， 而我们可以在任何时候重新应用这些改动（甚至在不同的分支上）。</p>
<blockquote>
<p>迁移到 <code>git stash push</code></p>
<p>截至 2017 年 10 月下旬，Git 邮件列表上进行了广泛讨论，该讨论中弃用了 <code>git stash save</code> 命令， 代之以现有 <code>git stash push</code> 命令。主因是<code>git stash push</code> 引入了贮藏选定的 <strong>路径规范</strong> 的选项， 而有些东西 <code>git stash save</code> 不支持。</p>
<p><code>git stash save</code> 不会很快就消失，所以不用担心它突然不见。 不过你可能想要迁移到 <code>push</code> 来获取新功能。</p>
</blockquote>
<h1 id="二、仓库准备"><a href="#二、仓库准备" class="headerlink" title="二、仓库准备"></a><font size=3>二、仓库准备</font></h1><h2 id="1-初始化仓库并提交"><a href="#1-初始化仓库并提交" class="headerlink" title="1. 初始化仓库并提交"></a><font size=3>1. 初始化仓库并提交</font></h2><p>我们在本地准备一个测试的仓库，并做一次提交，另外需要直接创建一个分支：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git init</span></span><br><span class="line">Initialized empty Git repository in D:/git_test/.git/</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">touch</span> readme.md</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">touch</span> test.md</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git add .</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git commit -m <span class="string">&quot;feat:首次提交&quot;</span></span></span><br><span class="line">[master (root-commit) 6fdcbbf] feat:首次提交</span><br><span class="line"> 2 files changed, 0 insertions(+), 0 deletions(-)</span><br><span class="line"> create mode 100644 readme.md</span><br><span class="line"> create mode 100644 test.md</span><br><span class="line"><span class="meta prompt_"> </span></span><br><span class="line"><span class="meta prompt_"> $ </span><span class="language-bash">git branch dev</span></span><br></pre></td></tr></table></figure>

<h2 id="2-文件内容与提交记录"><a href="#2-文件内容与提交记录" class="headerlink" title="2. 文件内容与提交记录"></a><font size=3>2. 文件内容与提交记录</font></h2><p>我们记录一下各个分支上这两个文件的内容：</p>
<h3 id="2-1-master分支"><a href="#2-1-master分支" class="headerlink" title="2.1 master分支"></a><font size=3>2.1 master分支</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624202757705.png" alt="image-20230624202757705" style="zoom:50%;" />

<h3 id="2-2-dev分支"><a href="#2-2-dev分支" class="headerlink" title="2.2 dev分支"></a><font size=3>2.2 dev分支</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624202832487.png" alt="image-20230624202832487" style="zoom:50%;" />

<h1 id="三、贮藏工作"><a href="#三、贮藏工作" class="headerlink" title="三、贮藏工作"></a><font size=3>三、贮藏工作</font></h1><p>这里贮藏的修改我们在master分支上进行。</p>
<h2 id="1-产生文件改动"><a href="#1-产生文件改动" class="headerlink" title="1. 产生文件改动"></a><font size=3>1. 产生文件改动</font></h2><p>为了演示贮藏，我们需要进入项目并改动几个文件，然后可以暂存其中的一个改动：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624203432533.png" alt="image-20230624203432533" style="zoom:50%;" />

<p>如果运行 <code>git status</code>，可以看到有改动的状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git status</span></span><br><span class="line">On branch master</span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)</span><br><span class="line">        modified:   readme.md</span><br><span class="line"></span><br><span class="line">Changes not staged for commit:</span><br><span class="line">  (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)</span><br><span class="line">  (use &quot;git restore &lt;file&gt;...&quot; to discard changes in working directory)</span><br><span class="line">        modified:   test.md</span><br></pre></td></tr></table></figure>

<p>我们修改仓库中的两个文件，但是，我们只将readme文件添加到暂存区，这个时候就会出现上边的文件状态。</p>
<h2 id="2-切换分支"><a href="#2-切换分支" class="headerlink" title="2. 切换分支"></a><font size=3>2. 切换分支</font></h2><p>我们现在不提交上边做的改动，但是又想切换分支，我们来尝试一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git checkout dev</span> </span><br><span class="line">Switched to branch &#x27;dev&#x27;</span><br><span class="line">M       readme.md</span><br><span class="line">M       test.md</span><br></pre></td></tr></table></figure>

<p>我们现在看一下处于哪个分支：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git branch</span> </span><br><span class="line">* dev</span><br><span class="line">  master</span><br></pre></td></tr></table></figure>

<p>会发现，我们切换分支成功了，我们看一下现在的dev分支下的文件状态：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624074209583.png" alt="image-20230624074209583" style="zoom:50%;" />

<p>会发现，居然和master分支一样，这两个文件都被修改了，还添加到了暂存库，这不就混乱了吗？其实在使用git的过程中，多数时候切换分支的时候发现原来所处的分支中有没有提交的记录时，是会停止切换分支，报错的，但是这里没有，就有些奇怪，不过一样的结果。这里虽然没报错，但还是以影响到了我们dev分支的文件，这个时候我们并不想把做了一半的工作进行提交，但是又想去另一个分支做一些事情。这个时候就可以用贮藏命令啦。</p>
<p>我们这里先切换回master分支：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git checkout master</span> </span><br><span class="line">Switched to branch &#x27;master&#x27;</span><br><span class="line">M       readme.md</span><br><span class="line">M       test.md</span><br></pre></td></tr></table></figure>

<h2 id="3-贮藏修改"><a href="#3-贮藏修改" class="headerlink" title="3. 贮藏修改"></a><font size=3>3. 贮藏修改</font></h2><h3 id="3-1-命令说明"><a href="#3-1-命令说明" class="headerlink" title="3.1 命令说明"></a><font size=3>3.1 命令说明</font></h3><p>贮藏命令是<code>stash</code>，如下所示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git stash</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">或者</span></span><br><span class="line">git stash push</span><br></pre></td></tr></table></figure>

<p>贮藏命令可以将我们相对于最新一次提交记录的差异存储在栈上。另外Git允许我们做多次贮藏，后边再看。</p>
<h3 id="3-2-使用实例"><a href="#3-2-使用实例" class="headerlink" title="3.2 使用实例"></a><font size=3>3.2 使用实例</font></h3><p>上边我们已经回到了master分支，我们执行贮藏命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git stash push</span></span><br><span class="line">Saved working directory and index state WIP on master: 6fddbcf feat:首次提交</span><br></pre></td></tr></table></figure>

<p>然后我们来看一下当前的文件状态和提交记录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git status</span> </span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working tree clean</span><br></pre></td></tr></table></figure>

<p>发现，工作区是干净的，并且也没有产生提交记录，这个时候我们再切换分支就不会有任何问题啦。这时候再去看文件，就会发现文件中我们所做的修改都消失啦。</p>
<h2 id="4-查看贮藏内容"><a href="#4-查看贮藏内容" class="headerlink" title="4. 查看贮藏内容"></a><font size=3>4. 查看贮藏内容</font></h2><p>我们要是想查看贮藏了哪些内容怎么办?</p>
<h3 id="4-1-命令说明"><a href="#4-1-命令说明" class="headerlink" title="4.1 命令说明"></a><font size=3>4.1 命令说明</font></h3><p>我们可以通过以下命令查看贮藏的内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash list</span><br></pre></td></tr></table></figure>

<h3 id="4-2-贮藏信息说明"><a href="#4-2-贮藏信息说明" class="headerlink" title="4.2 贮藏信息说明"></a><font size=3>4.2 贮藏信息说明</font></h3><p>我们查看贮藏内容的时候一般会有如下打印信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">stash@&#123;0&#125;: WIP on branch_name: commit_id commit_info</span><br><span class="line">stash@&#123;1&#125;: WIP on branch_name: commit_id commit_info</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">......</span></span><br></pre></td></tr></table></figure>

<ul>
<li>stash@{1} ：表示贮藏修改的编号，数字越小，贮藏时间越靠前，数字越大，贮藏越旧。</li>
<li>branch_name ：进行贮藏操作的时候所处的分支，也就表示了这一个贮藏是哪一个分支上进行的贮藏。</li>
<li>commit_id ：贮藏的时候，此分支上最新的条记录的hash值，也就是在哪个提交记录的基础上做的修改被贮藏了。</li>
<li>commit_info ：贮藏的时候，此分支上最新的条记录的提交信息。</li>
</ul>
<h3 id="4-3-使用实例"><a href="#4-3-使用实例" class="headerlink" title="4.3 使用实例"></a><font size=3>4.3 使用实例</font></h3><p>我们来看一下刚才贮藏的内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git stash list</span></span><br><span class="line">stash@&#123;0&#125;: WIP on master: 6fddbcf feat:首次提交</span><br></pre></td></tr></table></figure>

<p>这里可以注意下，每一次的贮藏，前边都会有一个编号，例如<code>stash@&#123;0&#125;</code>中的0就是这一次贮藏的编号，后边会有用。</p>
<h1 id="四、应用贮藏"><a href="#四、应用贮藏" class="headerlink" title="四、应用贮藏"></a><font size=3>四、应用贮藏</font></h1><p>我们切换分支，完成相应的任务后，要继续回到master分支继续刚才没有完成的事情，这个时候就需要恢复贮藏的内容，也可以叫<strong>应用贮藏</strong>。</p>
<h2 id="1-命令说明"><a href="#1-命令说明" class="headerlink" title="1. 命令说明"></a><font size=3>1. 命令说明</font></h2><p>我们可以通过以下命令来恢复贮藏的内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash apply</span><br></pre></td></tr></table></figure>

<p>那要是有多个贮藏呢？就像刚才的情况。如果想要应用其中一个更旧的贮藏，可以通过名字指定它，像这样：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash apply stash@&#123;n&#125;</span><br></pre></td></tr></table></figure>

<p><code>n</code>就表示贮藏的编号，<code>n = 0</code>表示最近一次注册那个，数字越大，表示贮藏越旧。 <strong>如果不指定一个贮藏，Git 认为指定的是最近的贮藏</strong>。</p>
<h2 id="2-使用实例"><a href="#2-使用实例" class="headerlink" title="2. 使用实例"></a><font size=3>2. 使用实例</font></h2><p>我们来试一下恢复最近一次的贮藏：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash apply </span><br></pre></td></tr></table></figure>

<p>然后我们会看到以下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624080518416.png" alt="image-20230624080518416" style="zoom:50%;" />

<p>我们会发现，之前做的修改回到了工作区，但是有一个变化，那就是，两个文件的修改都出现在了<code>Changes not staged for commit</code>的下边，看起来像是吧暂存区中的修改也撤回到未使用<code>git add</code>之前的状态了。然后我们查看文件内容的话，就可以看到 Git 重新修改了当我们保存贮藏时撤消的的内容了。</p>
<h2 id="4-可能会产生冲突？"><a href="#4-可能会产生冲突？" class="headerlink" title="4. 可能会产生冲突？"></a><font size=3>4. 可能会产生冲突？</font></h2><p>在上边恢复贮藏的实例中，当我们尝试应用贮藏时有一个干净的工作目录，并且尝试将它应用在保存它时所在的分支。 <strong>并不是必须要有一个干净的工作目录，或者要应用到同一分支才能成功应用贮藏。 可以在一个分支上保存一个贮藏，切换到另一个分支，然后尝试重新应用这些修改</strong>。 当应用贮藏时工作目录中也可以有修改与未提交的文件——如果有任何东西不能干净地应用，Git 会产生合并冲突。</p>
<p>我们可以来尝试一下，我么还是在master分支上进行操作。我们知道贮藏修改后，工作区的文件会恢复到修改之前的状态，刚才我们应用了贮藏，这里我们先撤销文件的修改，也就是会回到应用贮藏之前，我们直接执行下边的命令即可：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- .</span><br></pre></td></tr></table></figure>

<p>然后当前工作区的文件就回到了首次提交的时候的空文件了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204122573.png" alt="image-20230624204122573" style="zoom:50%;" />

<p>我们知道上边贮藏的时候的修改中我们修改了这两个文件的第一行，所以我们再次修改这两个文件的第一行：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204424836.png" alt="image-20230624204424836" style="zoom:50%;" />

<p>然后再应用贮藏，这个时候就会出现类似以下的报错：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624204534493.png" alt="image-20230624204534493" style="zoom:50%;" />

<p>这种情况下就无法应用贮藏了这里还是需要注意一下的。演示完毕后我们清空一下这个工作区，方便后续的测试学习：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- .</span><br></pre></td></tr></table></figure>



<h2 id="5-回到贮藏的状态？"><a href="#5-回到贮藏的状态？" class="headerlink" title="5. 回到贮藏的状态？"></a><font size=3>5. 回到贮藏的状态？</font></h2><p>还记得前边我们应用贮藏的时候，发现恢复的修改都是没有被提交到暂存区的，但是我们进行贮藏的时候，是吧readme文件提交到暂存区了的，那么如何在应用贮藏的时候回到注册那个修改的时候的状态呢？</p>
<h3 id="5-1-命令说明"><a href="#5-1-命令说明" class="headerlink" title="5.1 命令说明"></a><font size=3>5.1 命令说明</font></h3><p>想要完全跟贮藏那个的时候状态一样，我们需要加上&#96;&#96;–index&#96;参数：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash apply --index</span><br></pre></td></tr></table></figure>

<h3 id="5-2-使用实例"><a href="#5-2-使用实例" class="headerlink" title="5.2 使用实例"></a><font size=3>5.2 使用实例</font></h3><p>我们接下来来看一下，我们执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash apply --index</span><br></pre></td></tr></table></figure>

<p>然后我们会看到如下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624205116412.png" alt="image-20230624205116412" style="zoom:50%;" />

<p>发现这个时候，应用的贮藏跟我们贮藏修改的时候的状态一模一样啦。</p>
<h1 id="五、移除贮藏"><a href="#五、移除贮藏" class="headerlink" title="五、移除贮藏"></a><font size=3>五、移除贮藏</font></h1><h2 id="1-情况说明"><a href="#1-情况说明" class="headerlink" title="1. 情况说明"></a><font size=3>1. 情况说明</font></h2><p>还记得上一步，我们使用<code>git stash apply --index</code>命令应用了一次贮藏，应用完贮藏，贮藏的记录还在吗？我们来看一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git stash list</span> </span><br><span class="line">stash@&#123;0&#125;: WIP on master: 6fddbcf feat:首次提交</span><br></pre></td></tr></table></figure>

<p>会发现贮藏的信息还在，如果不移除的话，它将会一直存在于栈上。</p>
<h2 id="2-命令说明"><a href="#2-命令说明" class="headerlink" title="2. 命令说明"></a><font size=3>2. 命令说明</font></h2><p>我们可以使用以下命令来移除贮藏记录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git stash drop stash@&#123;n&#125;</span><br></pre></td></tr></table></figure>

<p><code>stash@&#123;n&#125;</code>就表示贮藏列表前边的那个编号。</p>
<h2 id="3-使用实例"><a href="#3-使用实例" class="headerlink" title="3. 使用实例"></a><font size=3>3. 使用实例</font></h2><p>我们来实际验证一下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-10-%E8%B4%AE%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86/img/image-20230624205600592.png" alt="image-20230624205600592" style="zoom:50%;" />

<p>会发现，贮藏的记录确实消失了。</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/5abe0a5e.html">LV01-Git-04-Git本地仓库-10-贮藏与清理</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 15:14</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/5abe0a5e.html" title="LV01-Git-04-Git本地仓库-10-贮藏与清理">https://sumumm.github.io/post/5abe0a5e.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/754a0881.html" rel="prev" title="LV01-Git-05-远程仓库-01-GitHub简介">
                  <i class="fa fa-angle-left"></i> LV01-Git-05-远程仓库-01-GitHub简介
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/6805396b.html" rel="next" title="LV01-Git-04-Git本地仓库-09-rebase">
                  LV01-Git-04-Git本地仓库-09-rebase <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
